﻿using System;
using System.Collections.Generic;
using System.Text;
using FluorineFx;

using Game.Server.Socket;

namespace Game.Server.MainApp
{
    public class UserBase
    {
        private SocketServer _socketServer;
        private Session _sessiion;
        private SocketPack _socketPack;

        public UserBase(SocketServer socketServer, Session sessiion, SocketPack socketPack)
        {
            _socketServer = socketServer;
            _sessiion = sessiion;
            _socketPack = socketPack;

            setEvent();
        }

        public void setEvent()
        {
            switch (_socketPack.PackCode)
            {
                case (int)DataPackCode.UserBaseCode.USER_LOGIN:
                    userLogin();
                    break;
                case (int)DataPackCode.UserBaseCode.USER_LIST:
                    userList();
                    break;
            }
        }

        public void userLogin()
        {
            SocketPack sp = new SocketPack((int)DataPackCode.UserBaseCode.ROOT_CODE, (int)DataPackCode.UserBaseCode.USER_LOGIN, 1);
            if (_socketPack.PackData["userName"].ToString() == "devin")
            {
                sp.AddDataItem("result", true);
            }
            else
            {
                sp.AddDataItem("result", false);
            }
            _socketServer.Send(_sessiion, sp);
        }

        public void userList()
        {
            int sex = (int)_socketPack.PackData["sex"];
            SocketPack sp2 = new SocketPack(0x01, 0x02, 1);
            List<ASObject> oList = new List<ASObject>();
            ASObject item;

            if (sex == 0)
            {
                for (int i = 0; i < 10; i++)
                {
                    item = new ASObject();
                    item.Add("UserName", "男用户姓名" + i);
                    item.Add("NickName", "男用户昵称" + i);
                    oList.Add(item);
                }
            }
            else if (sex == 1)
            {
                for (int i = 0; i < 5; i++)
                {
                    item = new ASObject();
                    item.Add("UserName", "女用户姓名" + i);
                    item.Add("NickName", "女用户昵称" + i);
                    oList.Add(item);
                }
            }

            sp2.AddDataItem("list", oList);
            _socketServer.Send(_sessiion, sp2);
        }
    }
}
